#ifndef COMMON_STORE_H
#define COMMON_STORE_H

#include <map>

namespace cmn {

	template<typename TKey, typename TValue>
	class Store
	{
		typedef TValue( *Retriever )( TKey item );

	public:
		Store( Retriever retriever ) {m_retriever = retriever;}

		TValue Get( TKey key ) {
			typename std::map<TKey, TValue>::iterator it = m_map.find( key );
			if( it != m_map.end() )
				return ( *it ).second;

			TValue newValue = m_retriever( key );
			m_map[key] = newValue;
			return newValue;
		}

	private:
		TValue Create( TKey key );

	private:
		Retriever m_retriever;
		std::map<TKey, TValue> m_map;
	};
}
#endif
